package pe.edu.upc.dsd.mercadolibreres;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UserDao extends BaseDAO{

	
public void  GuardarUser(User vo) throws DAOExcepcion {
		
		String query = "INSERT INTO user(iduser, nombre, " +
				"pass) VALUES (?,?,?)";
		Connection con = null;
		PreparedStatement stmt = null;
		try {
			con = ConexionBD.obtenerConexion();
			stmt = con.prepareStatement(query);
			
			stmt.setInt(1, vo.getId());
			stmt.setString(2, vo.getNombre());
			stmt.setString(3, vo.getPass());
	
			
			int i = stmt.executeUpdate();
			if (i != 1) {
				throw new SQLException("No se pudo insertar");
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}
		
		
	}
}
